wayland: Improve guessing of popup placement for detached popup menus
authorJonas Ådahl <jadahl@gmail.com>
Fri, 5 Jun 2015 05:29:22 +0000 (13:29 +0800)
committerJonas Ådahl <jadahl@gmail.com>
Wed, 10 Jun 2015 03:28:32 +0000 (11:28 +0800)
If a menu was not attached to any widget, we try to calculate its
position given where the grabbed pointer is and what window has its
focus. Previously we failed to do so if a "transfer window" was used
for the grab, and this patch adds a code path that, if the menu window
itself didn't have the grab, look for the transfer window and get the
grab device from there.

https://bugzilla.gnome.org/show_bug.cgi?id=748951

gdk/wayland/gdkwindow-wayland.c

index 590ff4d8c1735444ccfb01c08de68796b1fd6979..fded03a5187447ac46c853454f260170001f74af 100644 (file)
@@ -1184,12 +1184,42 @@ gdk_wayland_window_map (GdkWindow *window)
       /* Popup menus can appear without a transient parent, which means they
        * cannot be positioned properly on Wayland. This attempts to guess the
        * surface they should be positioned with by finding the surface beneath
-       * the device that created the grab for the popup window
+       * the device that created the grab for the popup window.
        */
       if (!impl->transient_for && impl->hint == GDK_WINDOW_TYPE_HINT_POPUP_MENU)
         {
-          transient_for = gdk_device_get_window_at_position (impl->grab_device, NULL, NULL);
-          transient_for = gdk_window_get_toplevel (transient_for);
+          GdkDevice *grab_device;
+
+          /* The popup menu window is not the grabbed window. This may mean
+           * that a "transfer window" (see gtkmenu.c) is used, and we need
+           * to find that window to get the grab device. If so is the case
+           * the "transfer window" can be retrieved via the
+           * "gdk-attached-grab-window" associated data field.
+           */
+          if (!impl->grab_device)
+            {
+              GdkWindow *attached_grab_window =
+                g_object_get_data (G_OBJECT (window),
+                                   "gdk-attached-grab-window");
+              if (attached_grab_window)
+                {
+                  GdkWindowImplWayland *attached_impl =
+                    GDK_WINDOW_IMPL_WAYLAND (attached_grab_window->impl);
+                  grab_device = attached_impl->grab_device;
+                  transient_for =
+                    gdk_device_get_window_at_position (grab_device,
+                                                       NULL, NULL);
+                }
+            }
+          else
+            {
+              grab_device = impl->grab_device;
+              transient_for =
+                gdk_device_get_window_at_position (grab_device, NULL, NULL);
+            }
+
+          if (transient_for)
+            transient_for = gdk_window_get_toplevel (transient_for);
 
           /* If the position was not explicitly set, start the popup at the
            * position of the device that holds the grab.